<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/9/27
 * Time: 10:58
 */
namespace app\index\controller;


use think\Db;
use think\Controller;

class Real extends Base{


    public $user_model = null;


    public $user_attribute = null;


    public $user_real = null;



    public function _initialize()
    {
        parent::_initialize();

        $this->user_real = new \app\common\model\user\Real;
    }





    //提交审核
    public function apply_act(){

        $input = input("post.");
        $uid = $this->uid;
        file_put_contents( "error_apply.txt", "uid:". $this->uid, FILE_APPEND);
        //编辑用户的值
        $data = [
            "username"=>$input["name"],
            "gender"=>$input["sex"]=="男"?"1":"2",
            "age"=>$input["age"],
            "tao_bao_no"=>$input["taobao"],
            "qq"=>$input["qq"],
        ];
        $data_attr = [
            "bank_name"=>$input["bankname"],
            "bank_no"=>$input["account"],
            "address"=>$input["address"],
            "address_detail"=>$input["addrDetail"],
            "wx_code"=>$input["qrcode"],
        ];
        $data_real = [
            "after_safe_img"=>$input["shouhou"],
            "tao_gas_img"=>$input["taoqizhi"],
            "tao_flower_img"=>$input["huabei"],
            "tao_exam_img"=>$input["tijian"],
            "tao_baby_img"=>$input["baobei"],
            "tao_evaluate_img"=>$input["pingjia"],
            "real_status"=>1
        ];
        Db::startTrans();
        try{
                Db::name("user")->where("uid",$uid)->setField($data);
                Db::name("user_attribute")->where("uid",$uid)->setField($data_attr);
                $user_real = Db::name("user_real")->where("uid",$uid)->find();
                if($user_real) {
                    Db::name("user_real")->where("uid",$uid)->setField($data_real);
                }else{
                    $data_real["uid"] = $uid;
                    Db::name("user_real")->insert($data_real);

                }
                Db::name("user_bank")->insert([
                    "uid" => $uid,
                    "bank_person"=>$input["name"],
                    "bank_name"=>$input["bankname"],
                    "bank_code"=>$input["account"],
                    "created_time"=>time(),
                    "updated_time"=>time()
                ]);
                Db::commit();
                renderJson("成功提交，等待审核",1);

        }catch (\Exception $e){
            file_put_contents( "error_apply.txt", "errror:".$e->getMessage(), FILE_APPEND);
            renderJson($e->getMessage(),0);

        }



    }


}